package com.ala4.oxcafe.boot.async;

import com.ala4.oxcafe.async.AsyncTemplate;
import com.ala4.oxcafe.boot.repository.ExportTaskDTO;
import com.ala4.oxcafe.boot.repository.ExportTaskRepository;
import com.ala4.oxcafe.enums.AsyncTaskStateEnum;
import jakarta.annotation.Resource;

/**
 * 异步excel导出模版
 *
 * @author PING
 * @version 1.0.0
 * @date 2025/8/1 17:53
 */
public abstract class ExportAsyncTemplate implements AsyncTemplate<ExportTaskDTO> {

    @Resource
    protected ExportTaskRepository exportTaskRepository;

    @Override
    public void beforeSubmit(ExportTaskDTO dto) {
        // 提交任务前插入到数据库
        exportTaskRepository.insert(dto);
    }

    public void updateTaskStatus(ExportTaskDTO exportTaskDTO, AsyncTaskStateEnum asyncTaskStateEnum) {
        exportTaskDTO.setState(asyncTaskStateEnum);
        exportTaskRepository.update(exportTaskDTO);
    }
}
